

import {downloadFile,filedownload, UploadFile, } from "@/api/system";
const relatedfile = {
  data() {
    return {
      fileListMixin:[],
    }
  },
  methods:{
    // 相关材料附件上传
    submitUploadMixin(param) {
      const formData = new FormData();
      formData.append(param.file.uid, param.file);
      UploadFile(formData,{fileType:'0'},param).then(response => {
        if (response.data.code == 0) {
          this.fileListMixin.push({name: param.file.name, url: response.data.data});
          this.$notify({
            title: "成功",
            message: "上传成功",
            type: "success",
            duration: 2000
          });
        }
      }).catch(response => {
        this.fileListMixin = [];
        this.$notify({
          title: "失败",
          message: "上传失败",
          type: "error",
          duration: 2000
        });

      })
    },
    // 相关材料附件修改
    fileChangeMixin(file){
    },
    // 相关材料附件移除
    handleRemoveMixin(file, fileList) {
      this.fileListMixin = fileList;
    },
    // 相关材料点击文件列表时
    handlePreviewMixin(file) {
      filedownload(file.url).then(response => {
        if(response.status==200){
          this.downloadMixin(response.data,file.name)
        }
      }).catch((error) => {

      })
    },
    // 下载文件
    downloadMixin (data,filename) {
      if (data==null) {

      }else{
        let url = window.URL.createObjectURL(new Blob([data]));
        let link = document.createElement('a');
        link.style.display = 'none';
        link.href = url;
        link.setAttribute('download',filename );
        document.body.appendChild(link);
        link.click()
      }
    },
  }


};

export default relatedfile;
